import {
	defineStore
} from 'pinia'
export const useMyStore = defineStore('myStore', {

	state() {
		return {
			profile: uni.getStorageSync('profile') || null,
			openid: uni.getStorageSync('openid') || '',
			access_token: uni.getStorageSync('access_token') || '',
			user_id:uni.getStorageSync('user_id') || '',
			avatar: uni.getStorageSync('avatar') || '',
			nickName: uni.getStorageSync("nickName") || '微信用户',
			phone:uni.getStorageSync("phone") || '',
			jugleCode:"10000"
		}
	},

	actions: {
		setAvatar(avatar) {
			this.avatar = avatar;
			uni.setStorageSync('avatar', avatar);
		},
		clearAvatar() {
			this.avatar = null;
			uni.clearStorageSync('avatar')
		},
		setNickname(nickName) {
			this.nickName = nickName;
			uni.setStorageSync('nickName',nickName);
		},
		clearNickname() {
			this.nickName = null;
			uni.clearStorageSync('nickName')
		},
		setPhone(phone) {
			this.phone = phone;
			uni.setStorageSync('phone',phone);
		},
		clearPhone() {
			this.phone = null;
			uni.clearStorageSync('phone')
		},
		setUser_id(user_id){
			this.user_id = user_id;
			uni.setStorageSync('user_id',user_id);
		},
		clearUser_id(){
			this.user_id = ""
			uni.clearStorageSync('user_id')
		},
		setProfile(profile) {
			this.profile = profile;
			uni.setStorageSync('profile', profile);
		},
		clearProfile() {
			this.profile = null;
			uni.clearStorageSync('profile')
		},
		setOpenid(openid) {
			this.openid = openid;
			uni.setStorageSync('openid', openid);
		},
		clearOpenid() {
			this.openid = '';
			uni.clearStorageSync('openid')
		},
		setAccessToken(accessToken) {
			this.access_token = accessToken;
			uni.setStorageSync('access_token', accessToken);
		},
		clearAccessToken() {
			this.access_token = '';
			uni.clearStorageSync('access_token')
		},
		setJungleCode(jugleCode){
			this.jugleCode = jugleCode
		}
	},
})